<?php
namespace App\Admin\Controllers\Basics;

use App\Models\Basics\ExpressCompany;
use App\Models\Basics\SysPlat;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
class ExpressCompanyController extends AdminController{

    protected $title = '物流公司';

    protected function grid()
    {
        $grid = new Grid(new ExpressCompany());
        $grid->model()->orderByDesc('id');
        $grid->column('id','ID')->style('width: 5%');
        $grid->column('name','公司名称');
        $grid->column('name_en','公司名称（外文名称）');
        $grid->column('code','公司编码');
        $grid->column('platform_type','归属平台')->display(function ($value){
            return SysPlat::$_platformType[$value];
        });

        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableDelete();
            $actions->disableView();
        });

        $grid->disableRowSelector();
        $grid->disableCreateButton();
        $grid->disableExport();
        $grid->disableFilter();
        $grid->quickSearch('name');
        $grid->quickCreate(function (Grid\Tools\QuickCreate $create) {
            $create->text('name', '名称')->creationRules(['required', "unique:b_express_company"],['required' => '名称必填','unique' => '名称已存在']);

            //$create->text('name_en', '名称（外文名称）')->creationRules(['required', "unique:b_express_company"],['unique' => '名称(外文)已存在']);
            //$create->text('code', '编码')->creationRules(['required', "unique:b_express_company"],['unique' => '编码已存在']);
            //$create->select('platform_type', '平台')->options(SysPlat::$_platformType);
        });
        return $grid;
    }

    public function form()
    {
        $form = new Form(new ExpressCompany());

        $form->hidden('id');

        $form->text('name', '名称')
            ->creationRules(['required', "unique:b_express_company"],['required' => '名称必填','unique' => '名称已存在'])
            ->updateRules(['required', "unique:b_express_company,name,{{id}}"],['required' => '名称必填','unique' => '名称已存在']);

        //$form->text('name_en', '名称(外文名称)');
        //$form->text('code', '编码');
        //$form->select('platform_type', '归属平台')->options(SysPlat::$_platformType);

        $form->tools(function (Form\Tools $tools) {
            $tools->disableView();
            $tools->disableDelete();
        });
        return $form;
    }
}
